<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>欢迎页</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="!showList" class="panel panel-default">
        <div class="panel-heading">Rap2配置信息</div>
		  <div class="form-group">
                      <div class="col-sm-2 control-label">rap2数据地址</div>
                      <div class="col-sm-10">
                          <input type="text" class="form-control" name="address" placeholder="rap2数据地址"/>
                      </div>
            </div>
			<div class="form-group">
                      <div class="col-sm-2 control-label">Cookie</div>
                      <div class="col-sm-10">
                          <input type="text" class="form-control" name="cookie" placeholder="Cookie值"/>
                      </div>
            </div>
		    <div class="form-group">
                      <div class="col-sm-2 control-label">Author</div>
                      <div class="col-sm-10">
                          <input type="text" class="form-control" name="auth" placeholder="模块开发者"/>
                      </div>
            </div>
		    <div class="form-group">
                      <div class="col-sm-2 control-label">接口名称</div>
                      <div class="col-sm-10">
                          <input type="text" class="form-control" name="interfaceName" placeholder="接口名称"/>
                      </div>
           </div>
		   <div class="form-group">
              <div class="col-sm-2 control-label"></div>
              <input type="button" class="btn btn-primary" id="btnSaveOrUpdate"  onclick="saveOrUpdate()" value="代码生成"/>
          </div>
    </div>
</div>
<script>
  function saveOrUpdate(){  debugger;
      var xhr = null;
      if (window.XMLHttpRequest) {
          //Mozilla chrome
          xhr = new XMLHttpRequest();
      } else {
          if (window.ActiveXObject) {
              //IE 浏览器
              try {
                  xhr = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (e) {
                  try {
                      //IE 浏览器
                      xhr = new ActiveXObject("Msxml2.XMLHTTP");
                  } catch (e) {
                  }
              }
          }
      }
      // 也可以使用POST方式，根据接口
      xhr.open('POST', "/yst-code/rap2/code", true);
      // 返回类型blob
      xhr.responseType = "blob";
      xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
      xhr.onload = function () { 
    	      debugger;
          //请求头为创建文件
          if (this.status == 201) {
              var content = this.getResponseHeader("content-disposition");
              var filename = new Date().getTime()+".zip";
              // this.response也就是请求的返回就是Blob对象
              var blob = this.response;
              var a = document.createElement('a');
              //一个字符串，表明该Blob对象所包含数据的MIME类型
              blob.type = "application/zip";
              var link = URL.createObjectURL(blob);
              a.href = link;
              a.download = filename;
              document.body.appendChild(a);
              if (!!window.ActiveXObject || "ActiveXObject" in window) {
                  window.navigator.msSaveOrOpenBlob(blob, filename);
              } else {
                  a.click()
              }
              //下载完成移除元素
              document.body.removeChild(a);
              //释放掉blob对象
              window.URL.revokeObjectURL(link);
          } else {
              layer.alert('生成错误！')
          }
      };
      //xhr.send(JSON.stringify($p));
  }
</script>
</body>
</html>